/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.service.transfer;

import com.wtkj.vo.dzzf.base.kfwd.VehicleInfo;
import com.wttech.dzzf.process.constant.UserConstants;
import com.wttech.dzzf.process.dao.DataTransferDao;
import com.wttech.sjhj.check.moduleSet.CheckVehicleUpload_9;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 数据迁移-车辆信息检测
 *
 * @author MaShibo
 * @date 2017/11/6.
 */
@Service
public class VehicleInfoCheckService {

    private static final Logger ERRORINFO = DataTransferService.ERRORINFO;


    @Resource
    private DataTransferDao dataTransferDao;


    void analyseVehicleInfo(VehicleInfo vehicleInfo) {

        checkVehicleInfoIsValid(vehicleInfo);

        String vehPlate = vehicleInfo.getVehPlate();
        Integer vehColor = vehicleInfo.getVehColor();
        VehicleInfo dzzfVehicleInfo = dataTransferDao.queryDzzfVehicleInfoByVehInfos(vehPlate, vehColor);
        if (dzzfVehicleInfo != null) {
            ERRORINFO.info("电子支付中已存在，车牌号【{}】，车牌颜色【{}】的车辆信息记录", vehPlate, vehColor);
        }

    }

    private void checkVehicleInfoIsValid(VehicleInfo vehicleInfo) {

        String vehicleInfoId = vehicleInfo.getVehicleInfoId();

        //车辆识别代码
        String vin = vehicleInfo.getVehiclelicNO();
        if (!StringUtils.equalsIgnoreCase(CheckVehicleUpload_9.checkVIN(vin), UserConstants.RIGHT)) {
            ERRORINFO.info("车辆信息{}，车辆识别代码【{}】错误", vehicleInfoId, vin);
        }

        //指定联系人姓名
        String contact = vehicleInfo.getContact();
        if (!StringUtils.equalsIgnoreCase(CheckVehicleUpload_9.checkContact(contact), UserConstants.RIGHT)) {
            ERRORINFO.info("车辆信息{}，指定联系人姓名【{}】错误", vehicleInfoId, contact);
        }
    }
}
